package macrochip.vison.com.gps.utils;

import android.util.Log;

import java.text.SimpleDateFormat;
import java.util.Date;

public final class log {
    public static String getFileLineMethod() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    StringBuffer toStringBuffer = new StringBuffer("[").append(
    traceElement.getFileName()).append(" | ").append(
    traceElement.getLineNumber()).append(" | ").append(
    traceElement.getMethodName()).append("()").append("]");
    return toStringBuffer.toString();
    }
    public static String file() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getFileName();
    }
 
    public static String func() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return traceElement.getMethodName();
    }
 
    public static String line() {
    StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
    return String.valueOf(traceElement.getLineNumber());
    }
 
    public static String curTime() {
    Date now = new Date(0);
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    return sdf.format(now);
 
    }
     
    public static void v(String msg) {
        StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
        StringBuffer toStringBuffer = new StringBuffer("[").append(
        traceElement.getFileName()).append(" | ").append(
        traceElement.getLineNumber()).append(" | ").append(
        traceElement.getMethodName()).append("()").append("]");
        String TAG = toStringBuffer.toString();
        Log.v(TAG, msg);
    }
    public static  void d(String msg) {
        StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
        StringBuffer toStringBuffer = new StringBuffer("[").append(
        traceElement.getFileName()).append(" | ").append(
        traceElement.getLineNumber()).append(" | ").append(
        traceElement.getMethodName()).append("()").append("]");
        String TAG = toStringBuffer.toString();
         
        Log.d(TAG , msg);
    }
     
    public static void i(String msg) {
        StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
        StringBuffer toStringBuffer = new StringBuffer("[").append(
        traceElement.getFileName()).append(" | ").append(
        traceElement.getLineNumber()).append(" | ").append(
        traceElement.getMethodName()).append("()").append("]");
        String TAG = toStringBuffer.toString();
        Log.i(TAG,msg);
    }
     
    public static void w(String msg) {
        StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
        StringBuffer toStringBuffer = new StringBuffer("[").append(
        traceElement.getFileName()).append(" | ").append(
        traceElement.getLineNumber()).append(" | ").append(
        traceElement.getMethodName()).append("()").append("]");
        String TAG = toStringBuffer.toString();
        Log.w(TAG,msg);
     }
 
     public static void e(String msg) {
        StackTraceElement traceElement = ((new Exception()).getStackTrace())[1];
        StringBuffer toStringBuffer = new StringBuffer("[").append(
        traceElement.getFileName()).append(" | ").append(
        traceElement.getLineNumber()).append(" | ").append(
        traceElement.getMethodName()).append("()").append("]");
        String TAG = toStringBuffer.toString();
        Log.e(TAG,msg);
     }

    public static String bytetoString(byte[] bytearray) {
        String result = "";
        char temp;
        int length = bytearray.length;
        for (int i = 0; i < length; i++) {
            temp = (char) bytearray[i];
            result += temp;
        }
        return result;
    }

    public static String AsciiStringToString(String content) {
        String result = "";
        int length = content.length() / 2;
        for (int i = 0; i < length; i++) {
            String c = content.substring(i * 2, i * 2 + 2);
            int a = hexStringToAlgorism(c);
            char b = (char) a;
            String d = String.valueOf(b);
            result += d;
        }
        return result;
    }

    /**
     * 十六进制字符串装十进制
     *
     * @param hex
     *            十六进制字符串
     * @return 十进制数值
     */
    public static int hexStringToAlgorism(String hex) {
        hex = hex.toUpperCase();
        int max = hex.length();
        int result = 0;
        for (int i = max; i > 0; i--) {
            char c = hex.charAt(i - 1);
            int algorism = 0;
            if (c >= '0' && c <= '9') {
                algorism = c - '0';
            } else {
                algorism = c - 55;
            }
            result += Math.pow(16, max - i) * algorism;
        }
        return result;
    }
}